package org.test.bla;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.Toast;

public class WebviewTestActivity extends Activity {
	
	private Handler mHandler = new Handler();
	private WebView mWebview = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        mWebview = new WebView(this);
        setContentView(mWebview);
        
        WebSettings webSettings = mWebview.getSettings();
        webSettings.setSavePassword(false);
        webSettings.setSaveFormData(false);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(false);

        mWebview.setWebChromeClient(new MyWebChromeClient());

        mWebview.addJavascriptInterface(new DemoJavaScriptInterface(), "myJsInterface");

        mWebview.loadUrl("file:///android_asset/the_html.html");
        
    }
    
    
    final class DemoJavaScriptInterface {

        DemoJavaScriptInterface() {
        }

        /**
         * This is not called on the UI thread. Post a runnable to invoke
         * loadUrl on the UI thread.
         */
        public void onResult(String value) {
        	Toast.makeText(WebviewTestActivity.this, value, Toast.LENGTH_LONG).show();
        }
        
    }

    
    final class MyWebChromeClient extends WebChromeClient {
    	
    	@Override
		public boolean onJsAlert(WebView view, String url, String message, JsResult result){
    		
    		result.confirm();
    		if(message.equals("submit_button")){
    			mWebview.loadUrl("javascript:triggerResultCallback()");
    		}
    		
			return true;    		
    	}
    	
    }
    
    
    
}